package com.wz.project.viewTmsCk.controller;

import java.util.List;

import com.wz.project.api.out.domain.TmsOutstockOutDetail;
import com.wz.project.api.out.service.ITmsOutstockOutDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.viewTmsCk.domain.ViewTmsCk;
import com.wz.project.viewTmsCk.service.IViewTmsCkService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 出库单据子表Controller
 * 
 * @author wz
 * @date 2024-01-21
 */
@Controller
@RequestMapping("/viewTmsCk/viewTmsCk")
public class ViewTmsCkController extends BaseController
{
    private String prefix = "viewTmsCk/viewTmsCk";

    @Autowired
    private IViewTmsCkService viewTmsCkService;

    @Autowired
    private ITmsOutstockOutDetailService tmsOutstockOutDetailService;

//    @RequiresPermissions("viewTmsCk:viewTmsCk:view")
    @GetMapping()
    public String viewTmsCk()
    {
        return prefix + "/viewTmsCk";
    }

    /**
     * 查询出库单据子表列表
     */
//    @RequiresPermissions("viewTmsCk:viewTmsCk:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewTmsCk viewTmsCk)
    {
        startPage();
        List<ViewTmsCk> list = viewTmsCkService.selectViewTmsCkList(viewTmsCk);
        return getDataTable(list);
    }

    /**
     * 导出出库单据子表列表
     */
    @RequiresPermissions("viewTmsCk:viewTmsCk:export")
    @Log(title = "出库单据子表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewTmsCk viewTmsCk)
    {
        List<ViewTmsCk> list = viewTmsCkService.selectViewTmsCkList(viewTmsCk);
        ExcelUtil<ViewTmsCk> util = new ExcelUtil<ViewTmsCk>(ViewTmsCk.class);
        return util.exportExcel(list, "viewTmsCk");
    }

    /**
     * 新增出库单据子表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库单据子表
     */
    @RequiresPermissions("viewTmsCk:viewTmsCk:add")
    @Log(title = "出库单据子表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewTmsCk viewTmsCk)
    {
        return toAjax(viewTmsCkService.insertViewTmsCk(viewTmsCk));
    }

    /**
     * 修改出库单据子表
     */
    @GetMapping("/edit/{truckNumber}")
    public String edit(@PathVariable("truckNumber") String truckNumber, ModelMap mmap)
    {
        ViewTmsCk viewTmsCk = viewTmsCkService.selectViewTmsCkById(truckNumber);
        mmap.put("viewTmsCk", viewTmsCk);
        return prefix + "/edit";
    }

    /**
     * 修改出库单据子表
     */
//    @GetMapping("/xiugai/{truckNumber}")
//    public String xiugai(@PathVariable("truckNumber") String truckNumber, ModelMap mmap)
//    {
//        ViewTmsCk viewTmsCk = viewTmsCkService.selectViewTmsCkById(truckNumber);
//        mmap.put("viewTmsCk", viewTmsCk);
//        return prefix + "/edit";
//    }

    /**
     * 修改出库单据子表
     */
    @RequestMapping("/xiugai")
    public String getStockList(ViewTmsCk viewTmsCk, ModelMap mmap){
        List<ViewTmsCk> viewTmsCks = viewTmsCkService.selectViewTmsCkList(viewTmsCk);
        mmap.put("viewTmsCk",viewTmsCks.get(0));
        return prefix + "/edit";
    }

    /**
     * 修改保存出库单据子表
     */
    @RequiresPermissions("viewTmsCk:viewTmsCk:edit")
    @Log(title = "出库单据子表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewTmsCk viewTmsCk)
    {
        TmsOutstockOutDetail tmsOutstockOutDetail = new TmsOutstockOutDetail();
        tmsOutstockOutDetail.setTruckNumber(viewTmsCk.getTruckNumber());
        tmsOutstockOutDetail.setOutOrder(viewTmsCk.getOutOrder());
        return toAjax(tmsOutstockOutDetailService.updateTmsOutstockOutDetail1(tmsOutstockOutDetail));
    }

    /**
     * 删除出库单据子表
     */
    @RequiresPermissions("viewTmsCk:viewTmsCk:remove")
    @Log(title = "出库单据子表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewTmsCkService.deleteViewTmsCkByIds(ids));
    }
}
